/**
 * Created by vincent on 2017/10/12.
 */
moduleBadge.controller("EditBadgeController", function ($$CambioConfig, $scope, $log, $state, LoadingService, UploadFileService,
                                                        ConstantService, DialogService, OldBadgeResource) {
    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
    });

    $scope.uploadImage = function ($files) {
        if ($files && $files[0]) {
            UploadFileService.uploadFile($files[0], $$CambioConfig.UPLOAD_URL, 'IMG', $scope).then(function (o) {
                $scope.editingBadge.picture = o.id;
            });
        }
    };

    $scope.cancel = function () {
        DialogService.close();
    };

    $scope.submit = function () {
        if ($scope.editBAForm.$valid) {
            Alert.confirm(function () {
                OldBadgeResource.update($scope.editingBadge, function (badgeResult) {
                    $log.debug("勋章更新结果", badgeResult);
                    angular.copy(badgeResult, $scope.currentBadge);
                    DialogService.close();
                    //LoadingService.hide();
                    Alert.success();
                }, function () {
                    //LoadingService.hide();
                });
            })
            //LoadingService.show();

        }
    };

});